package nodes;

import compiler.Compiler;
import compiler.SymbolTable;

import descriptors.AbstractDescr;
import descriptors.ConstDescr;
import descriptors.VarDescr;

public class ContNode extends ExpressionNode {

	private ExpressionNode node;

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ContNode(ExpressionNode node, int line, int column) {
		super(line, column);
		this.node = node;
	}

	@Override
	public AbstractDescr compile(SymbolTable symbolTable, Compiler compiler) {
		AbstractDescr descr = node.compile(symbolTable, compiler);
		if (!(descr instanceof ConstDescr)) {
			if (((descr instanceof VarDescr) && ((VarDescr) descr).isVar())) {
				compiler.write("CONT, 1");
			}
			int size = descr.getSize(); // Or the size of the type?
			compiler.write("CONT, " + size);
		}
		return descr;
	}
	
	public ExpressionNode node(){
	    return node;
	}

	@Override
	public void print() {
		trace("ContNode");
		node.print();
		unindent();
	}

}
